zebra: kernel_init function optimizations#22369
Conversation
Greptile SummaryThis PR refactors
Confidence Score: 3/5The refactoring is logically correct, but The socket initialization logic and group bitmask computation are faithfully preserved. The one concrete defect is in zebra/kernel_netlink.c — specifically Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[kernel_init] --> B[Compute groups / dplane_groups / ext_groups bitmasks]
B --> C[kernel_init_nlsock: netlink-listen\ngroups + ext_groups, fatal]
C -->|fail| X1[frr_exit_with_buffer_flush]
C -->|ok| D[kernel_init_nlsock: netlink-cmd\nno groups, fatal]
D -->|fail| X2[frr_exit_with_buffer_flush]
D -->|ok| E[kernel_init_nlsock: netlink-dp\nno groups, fatal]
E -->|fail| X3[frr_exit_with_buffer_flush]
E -->|ok| F[kernel_init_nlsock: netlink-dp-in\ndplane_groups, fatal]
F -->|fail| X4[frr_exit_with_buffer_flush]
F -->|ok| G[kernel_init_nlsock: generic-netlink-cmd\nno groups, warn-only]
G --> H{SOL_NETLINK defined?}
H -->|yes| I[setsockopt RTNLGRP_BRVLAN on dp-in]
I --> J[netlink_enable_ext_ack on cmd + dp-out]
J --> K{ge_netlink_cmd sock >= 0?}
K -->|yes| L[setsockopt NETLINK_EXT_ACK on ge_netlink_cmd]
L --> M[setsockopt NETLINK_CAP_ACK on dp-out]
K -->|no| M
M --> N[endif SOL_NETLINK]
H -->|no| N
N --> O[netlink_set_nonblock on all sockets]
O --> P{rcvbufsize set?}
P -->|yes| Q[netlink_recvbuf on all sockets]
P -->|no| R[netlink_install_filter on listen + dp-in]
Q --> R
R --> S[event_add_read for kernel_read]
S --> T[rt_netlink_init + ge_netlink_init]
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
zebra/kernel_netlink.c:1661
**Non-literal format string triggers `-Wformat-nonliteral`**
`configure.ac` unconditionally enables `-Wformat-nonliteral`, so passing `name_fmt` (a `const char *` parameter, not a string literal) as the format argument to `snprintf` will produce a compiler warning in every FRR build, and a hard build failure on CI where `--enable-werror` is used. Either annotate the parameter with `__attribute__((format(printf, 2, 0)))` / `PRINTFRR(2, 0)`, or replace the single `snprintf` with a call that makes the format an inline literal.
### Issue 2 of 2
zebra/kernel_netlink.c:81-84
Double blank line after the macro definition — FRR style uses a single blank line between top-level declarations.
```suggestion
#define RTNLGRP_BIT(g) ((uint32_t)1 << ((g) - 1))
static const struct message nlmsg_str[] = {
```
Reviews (1): Last reviewed commit: "zebra: kernel_init function optimization..." | Re-trigger Greptile |
| uint8_t ext_group_size, ns_id_t ns_id, | ||
| int nl_family, bool warn_only) | ||
| { | ||
| snprintf(nl->name, sizeof(nl->name), name_fmt, ns_id); |
There was a problem hiding this comment.
Non-literal format string triggers
-Wformat-nonliteral
configure.ac unconditionally enables -Wformat-nonliteral, so passing name_fmt (a const char * parameter, not a string literal) as the format argument to snprintf will produce a compiler warning in every FRR build, and a hard build failure on CI where --enable-werror is used. Either annotate the parameter with __attribute__((format(printf, 2, 0))) / PRINTFRR(2, 0), or replace the single snprintf with a call that makes the format an inline literal.
Prompt To Fix With AI
This is a comment left during a code review.
Path: zebra/kernel_netlink.c
Line: 1661
Comment:
**Non-literal format string triggers `-Wformat-nonliteral`**
`configure.ac` unconditionally enables `-Wformat-nonliteral`, so passing `name_fmt` (a `const char *` parameter, not a string literal) as the format argument to `snprintf` will produce a compiler warning in every FRR build, and a hard build failure on CI where `--enable-werror` is used. Either annotate the parameter with `__attribute__((format(printf, 2, 0)))` / `PRINTFRR(2, 0)`, or replace the single `snprintf` with a call that makes the format an inline literal.
How can I resolve this? If you propose a fix, please make it concise.16b8c8c to
b10e14f
Compare
Corrected the reported items. |
1775a78 to
b48c972
Compare
|
Tick the box to add this pull request to the merge queue (same as
|
b48c972 to
3b7701e
Compare
these changes are for improving the code maintainability and readability Signed-off-by: sri-mohan1 <sri.mohan@samsung.com>
3b7701e to
478e2ed
Compare
|
Review comments addressed and Rebased onto latest master. |
these changes are for improving the code maintainability and readability